package cn.knowei.miaosha.producer;

import cn.knowei.miaosha.enums.DelayTypeEnum;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: knowei
 * @Description:
 * @Date: Create in 19:28 2023-04-07
 */
@Component
public class DelayMessageProducer {
    public static final String DELAY_EXCHANGE_NAME = "delay.exchange";
    public static final String DELAY_QUEUE_A_NAME = "delay.queue.a";
    public static final String DELAY_QUEUE_B_NAME = "delay.queue.b";
    public static final String DELAY_QUEUE_A_ROUTING_KEY = "delay.queue.a.routingkey";
    public static final String DELAY_QUEUE_B_ROUTING_KEY = "delay.queue.b.routingkey";

    //死信交换机
    public static final String DEAD_LETTER_EXCHANGE_NAME = "dead.letter.exchange";
    //私信队列
    public static final String DEAD_LETTER_QUEUE_A_NAME = "dead.letter.queue.a";
    public static final String DEAD_LETTER_QUEUE_B_NAME = "dead.letter.queue.b";
    //
    public static final String DEAD_LETTER_QUEUE_A_ROUTING_KEY = "dead.letter.delay_10.routingkey";
    public static final String DEAD_LETTER_QUEUE_B_ROUTING_KEY = "dead.letter.delay_60.routingkey";

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void send(String message, DelayTypeEnum type) {
        switch (type) {
            case DELAY_10S:
                rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUE_A_ROUTING_KEY, message);
                break;
            case DELAY_60S:
                rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUE_B_ROUTING_KEY, message);
                break;
            default:
        }
    }
}
